
# ------------------------------------------------------------------------------
# Replication Materials
# 
# title: Coalition Size, Direct Democracy, and Public Spending
# journal: Journal of Public Policy
# authors: Patrick Emmenegger, Lucas Leemann, and André Walter
# date: Sept 2020
# ------------------------------------------------------------------------------




#### Descriptive Figures



'%ni%' <- Negate('%in%')
pdf("out/SpendTime.pdf",width=10,height=8)
CT <- unique(findat$canton[findat$LGcant==0 & findat$year==1850])
xlab <- c("1830", "1880", "1930", "1980", "2015")
ylab <- c("0","2","4","6","8","10")
par(mfrow=c(4,5),family="CMU Serif",mai=c(0.75,0.5,0.1,0.1))
for (i in CT){
  if (i %in% CT[c(1,6,11,16,21)])   plot(findat$year[findat$canton==i],findat$lnexp_pc[findat$canton==i], type="o",
                                         lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.3, bty="n", xaxt='n',
                                         xlim=c(1830,2020), ylim=c(0,10), xlab=paste("Canton",i), ylab="Log Expenditure p.c.", yaxt="n")
  
  if (i %ni% CT[c(1,6,11,16,21)])   plot(findat$year[findat$canton==i],findat$lnexp_pc[findat$canton==i], type="o",
                                         lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.3, bty="n", xaxt='n',
                                         xlim=c(1830,2020), ylim=c(0,10), xlab=paste("Canton",i), ylab="", yaxt="n")
  
  if (i %in% CT[15:19])   axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = xlab, tck=.03, cex.axis=0.8)
  if (i %in% CT[-c(15:19)])   axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = c("","","","",""),
                                   tck = 0.03, cex=0.8)
  if (i %in% CT[c(1,6,11,16,21)]) axis(side = 2, at = c(0,2,4,6,8,10), labels = ylab, tck=.03)
  if (i %in% CT[-c(1,6,11,16,21)])  axis(side = 2, at = c(0,2,4,6,8,10), labels = c("","","","","",""),
                                         tck = 0.03)
}
dev.off()



pdf("out/DDoverTime.pdf",width=10,height=8)
CT <- unique(findat$canton[findat$LGcant==0 & findat$year==1850])
xlab <- c("1830", "1880", "1930", "1980", "2015")
ylab <- c("0","",  "3","", "6")
par(mfrow=c(4,5),family="CMU Serif",mai=c(0.75,0.5,0.0,0.0))
for (i in CT){
  if (i %ni% CT[c(1,6,11,16,21)])  plot(findat$year[findat$canton==i],findat$index_law_init[findat$canton==i], type="o",
                                        lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.5, bty="n", xaxt='n',
                                        xlim=c(1830,2020), ylim=c(0,7), xlab=paste("Canton",i), ylab="", yaxt="n", tck = 0.03)
  
  if (i %in% CT[c(1,6,11,16,21)])  plot(findat$year[findat$canton==i],findat$index_law_init[findat$canton==i], type="o",
                                        lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.5, bty="n", xaxt='n',
                                        xlim=c(1830,2020), ylim=c(0,7), xlab=paste("Canton",i), ylab="Extent of DD", yaxt="n")
  axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = c("","","","",""), tck = 0.03)
  axis(side = 2, at = c(0,1.5,3,4.5, 6), labels = c("","","","",""), tck = 0.03)
  
  if (i %in% CT[15:19]) axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = xlab, cex.axis=0.8)
  if (i %in% CT[c(1,6,11,16,21)]) axis(side = 2, at = c(0,1.5,3,4.5, 6), labels = ylab, tck = 0.04)
  points(findat$year[findat$canton==i],findat$index_law_ref[findat$canton==i], type="o",
         lwd=2, col=rgb(255,0,0,80,maxColorValue = 255), pch=19, cex=.3)
}
dev.off()




pdf("out/FinRefTime.pdf",width=10,height=8)
CT <- unique(findat$canton[findat$LGcant==0 & findat$year==1850])
xlab <- c("1830", "1880", "1930", "1980", "2015")
ylab <- c("0","10","20","30","40","50")
par(mfrow=c(4,5),family="CMU Serif",mai=c(0.75,0.5,0.0,0.30))
for (i in CT){
  
  if (i %in% CT[9])  plot(findat$year[findat$canton==i&findat$refmon_adj1!=0],findat$refmon_adj1[findat$canton==i&findat$refmon_adj1!=0], #type="o",
                          lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                          xlim=c(1830,2025), ylim=c(0,130), xlab=paste("Canton",i), ylab="")
  
  if (i %ni% CT[c(1,6,9, 11,16,21)])  plot(findat$year[findat$canton==i&findat$refmon_adj1!=0],findat$refmon_adj1[findat$canton==i&findat$refmon_adj1!=0], #type="o",
                                           lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                                           xlim=c(1830,2025), ylim=c(0,50), xlab=paste("Canton",i), ylab="", yaxt="n")
  
  if (i %in% CT[c(1,6,11,16,21)])  plot(findat$year[findat$canton==i&findat$refmon_adj1!=0],findat$refmon_adj1[findat$canton==i&findat$refmon_adj1!=0], #type="o",
                                        lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                                        xlim=c(1830,2025), ylim=c(0,50), xlab=paste("Canton",i), ylab="Monetary Threshold p.c.", yaxt="n")
  
  
  
  axis(side = 1, at = c(1830,1880,1930,1980,2025), labels = c("","","","",""), tck = 0.03)
  axis(side = 2, at = c(0,10,20,30,40,50), labels = c("","","","","",""), tck = 0.03)
  
  if (i %in% CT[15:19]) axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = xlab, cex.axis=0.999, xpd=TRUE, las=2)
  if (i %in% CT[c(1,6,11,16,21)]) axis(side = 2, at = c(0,10,20,30,40,50), labels = ylab, cex.axis=0.9998)
  
}
dev.off()





pdf("out/NumParTime.pdf",width=10,height=8)
CT <- unique(findat$canton[findat$LGcant==0 & findat$year==1850])
xlab <- c("1830", "1880", "1930", "1980", "2015")
ylab <- c("0","2","4","6","8")
par(mfrow=c(4,5),family="CMU Serif",mai=c(0.75,0.5,0.0,0.30))
for (i in CT){
  
  if (i %in% CT[9])  plot(findat$year[findat$canton==i],findat$numpar[findat$canton==i], #type="o",
                          lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                          xlim=c(1830,2025), ylim=c(0,8), xlab=paste("Canton",i), ylab="")
  
  if (i %ni% CT[c(1,6,9, 11,16,21)])  plot(findat$year[findat$canton==i],findat$numpar[findat$canton==i], #type="o",
                                           lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                                           xlim=c(1830,2025), ylim=c(0,8), xlab=paste("Canton",i), ylab="", yaxt="n")
  
  if (i %in% CT[c(1,6,11,16,21)])  plot(findat$year[findat$canton==i],findat$numpar[findat$canton==i], #type="o",
                                        lwd=2, col=rgb(0,0,255,80,maxColorValue = 255), pch=19, cex=.75, bty="n", xaxt='n',
                                        xlim=c(1830,2025), ylim=c(0,8), xlab=paste("Canton",i), ylab="Monetary Threshold p.c.", yaxt="n")
  
  
  axis(side = 1, at = c(1830,1880,1930,1980,2025), labels = c("","","","",""), tck = 0.03)
  axis(side = 2, at = c(0,2,4,6,8), labels = c("","","","",""), tck = 0.03)
  
  if (i %in% CT[15:19]) axis(side = 1, at = c(1830,1880,1930,1980,2015), labels = xlab, cex.axis=0.999, xpd=TRUE, las=2)
  if (i %in% CT[c(1,6,11,16,21)]) axis(side = 2, at = c(0,2,4,6,8), labels = ylab, cex.axis=0.9998)
  
}
dev.off()